package com.gp.gback.system.common.util;


import com.github.pagehelper.Page;
import com.gp.gback.system.common.page.PagingResultDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by kongryan on 15/11/2.
 */
public class MybatisPaginationUtil {
    public static <T> PagingResultDTO<T> paginationResult(List<T> list){
        if(list instanceof Page) {
            PagingResultDTO<T> rs = new PagingResultDTO<T>();
            Page page = (Page)list;
            rs.setPageNum(page.getPageNum());
            rs.setPageSize(page.getPageSize());
            rs.setTotal((int) page.getTotal());
            rs.setMaxPage(page.getPages());
            rs.setItems(new ArrayList<T>(page));
            rs.setPageSize(page.size());

            return rs;
        }
        return null;
    }
}
